<script setup lang="ts">
defineOptions({
  name: 'ProductVue'
});

// 获取字典数据

import { useDict, transformDict } from '@/hooks/dict';
defineProps(["item"])
import useApply from '@/hooks/apply'
const { applyProduct } = useApply()
import { Star, StarFilled } from '@element-plus/icons-vue'
import { updateCollectionProduct } from '@/api/common';
import useUserStore from '@/stores/user';

const userStore = useUserStore();

const collectionProduct = (item) => {
  item.isCollected = item.isCollected == 0 ? 1 : 0
  updateCollectionProduct({
    productId: item.id,
    collectStatus: item.isCollected,
  }).then(res => {
    if (res.code == 200) {
      if (item.isCollected == 0) {
        ElMessage.success('取消收藏')
      } else {
        ElMessage.success('收藏成功')

      }
    }
  }).catch(err => {
    console.log(err)
  })
}

</script>
<template>
  <div class="market-content-box">
    <div class="cn-top">
      <div class="market-content-box-top relative">
        <span class="market-title">{{ item.productName }}</span>
        <span class="market-t market-t">{{ transformDict('productMainGuaranteeType', item.mainGuaranteeWay) }}</span>

        <div v-if="userStore.userType == 0" class="absolute top-3 right-3 w-5 h-5"
          @click.stop="collectionProduct(item)">
          <Star v-if="item.isCollected == 0" class="color-#DC8946" />
          <StarFilled v-else class="color-#DC8946 w-6 h-6" />
        </div>
      </div>
      <div class="market-content-box-center flex mb-4 items-center justify-between">
        <div class="market-content-box-left fl">
          <span class="left-top">{{ item.interestRateLimitLower }}-{{ item.interestRateLimitUpper }}%</span>
          <span class="left-bottom">利率范围</span>
        </div>
        <div class="market-content-box-left fl">
          <span class="left-top">{{ item.amountLimitLower }}-{{ item.amountLimitUpper }}万</span>
          <span class="left-bottom">贷款额度</span>
        </div>
        <div class="market-content-box-left fl">
          <span class="left-top">{{ item.loanPeriodLimitLower }}-{{ item.loanPeriodLimitUpper }}月</span>
          <span class="left-bottom">贷款期限</span>
        </div>
      </div>
      <div class="market-content-box-bottom flex items-center justify-between">
        <span class="marker-img ">
          <el-image class="w-full h-full" :src="item.orgLogo"> </el-image>
        </span>
        <span class="market-apply" @click.stop="applyProduct(item)">立即申请</span>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.market-content-box {
  // width: 360px;
  flex: 0 0 calc(33.333% - 1.7rem);
  background-color: #fff;
  -webkit-box-shadow: 0 0 10px 0 rgba(57, 120, 203, .1);
  box-shadow: 0 0 10px 0 rgba(57, 120, 203, .1);
  // margin: 28px 55px 10px 0;
  cursor: pointer;

  .market-content-box-bottom {

    border-top: 1px solid #edf2fa;


    .market-apply {
      height: 24px;
      line-height: 24px;
      border-radius: 6px;
      border: 1px solid #cacaca;
      font-size: 16px;
      color: #cacaca;
      padding: 4px 20px;
      vertical-align: middle;
      box-sizing: content-box;
      margin: 15px 30px;
      cursor: pointer;

      &:hover {
        background: #0051ff;
        color: #fff;
        border: none;
      }
    }

    .marker-img {
      width: 149px;
      height: 31px;
      box-sizing: content-box;
      display: block;
      margin-left: 23px;

      img {
        vertical-align: top;
        width: auto;
        height: auto;
        max-width: 100%;
        max-height: 100%;
      }
    }
  }

  .market-content-box-left {
    margin: 0 auto;
    line-height: 30px;
    text-align: center;

    .left-top {
      font-size: 23px;
      color: #ff693e;
      display: block;
    }

    .left-bottom {
      font-size: 14px;
      color: #666;
    }
  }

  .market-content-box-top {
    padding: 20px 0;
    text-align: center;

    .market-t {
      border: 1px solid #db5c5c;
      font-size: 10px;
      color: #db5c5c;
      padding: 1px 7px;
      margin-left: 8px;
      border-radius: 3px;
      display: inline-block;
      vertical-align: text-bottom;
    }

    .market-title {
      font-size: 18px;
      color: #282b45;
    }
  }
}
</style>
